Repository navigation
R23-T023: Property-based testing and boundary doctests for hex_to_rgb - #110
Open
mohammedsohail0301-dot wants to merge 1 commit into
Open
mohammedsohail0301-dot wants to merge 1 commit into
mohammedsohail0301-dot wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
Checklist
Description
This pull request completes Task R23-T023: property-based testing and verification of
conversions/hex_to_rgb.pyusing Hypothesis against mathematical properties and reference invariants, followed by adding boundary doctests to the function.A comprehensive property test suite (
work/R23-T023/test_hex_to_rgb_properties.py) tests the function across over 8,500 generated cases, verifying:rgb_to_hexround-trips exactly tof"rgb({r}, {g}, {b})".#RGBexpands to#RRGGBB(#prefix produce identical results.ValueError.int(..., 16)tolerates boundary whitespace/signs (e.g.,'#00000 '), which is formally documented inwork/R23-T023/PROPERTIES.md.Type of Change
Changes Made
conversions/hex_to_rgb.py:hex_to_rgb("#abc") -> 'rgb(170, 187, 204)'hex_to_rgb("#ff2000") -> 'rgb(255, 32, 0)''#'prefix:hex_to_rgb("FF0000") -> 'rgb(255, 0, 0)'andhex_to_rgb("123") -> 'rgb(17, 34, 51)'hex_to_rgb("#12345") -> ValueErrorandhex_to_rgb("") -> ValueErrorNote:section to explicitly document support for uppercase/lowercase and optional'#'prefix.ValueErrorraise statement are 100% preserved.work/R23-T023/:test_hex_to_rgb_properties.py: Hypothesis property test suite with 7 test functions covering round-trip bijection, 3-digit expansion, case/prefix invariance, error domain rejection, and edge cases.PROPERTIES.md: Detailed mathematical documentation of the color spaces, bijection formulations, property definitions, and Hypothesis discovery analysis.test_output.txt: Execution logs of doctests, pytest, hypothesis, ruff lint, ruff format, and ty type check.Testing & Verification
All automated tests passed cleanly:
python3 -m doctest -v conversions/hex_to_rgb.py-> 14/14 tests passed.uv run --with hypothesis --with pytest pytest work/R23-T023/test_hex_to_rgb_properties.py-> 7/7 passed in 1.67s (>8,500 generated cases).uv run --with pytest pytest --doctest-modules conversions/hex_to_rgb.py-> 1 passed in 0.02s.uvx ruff check conversions/hex_to_rgb.py work/R23-T023/test_hex_to_rgb_properties.py-> All checks passed.uvx ruff format --check conversions/hex_to_rgb.py work/R23-T023/test_hex_to_rgb_properties.py-> 2 files already formatted.uvx ty check --exit-zero conversions/hex_to_rgb.py-> 0 diagnostics.Additional Notes
student/E26B07F0850/R23-T023-upstream(andR23-T023-upstream) containing only the code change inconversions/hex_to_rgb.pyhas been prepared for future upstream submission.